/*
 * =====================================================================================
 *       Filename:  list_cmd.c
 *    Description:  
 *        Version:  2.0
 *        Created:  2017.06.03 17:51
 *         Author:  fujiajun (fjj), fujiajun@renren1.com
 *        Company:  HOOLINKS
 * =====================================================================================
 */

#include "xshell.h"

void list_cmd(char* param[PARAMNUM]){
    DIR* dir;
    struct dirent* ptr;

    // 对参数进行分析
    if(param[0] == NULL) {
        printf("list：缺少操作数\n");
    } else {
        // 打开目录并获取所有目录及文件命
        dir = opendir(param[0]);

        if (dir == NULL) {
            printf("list %s：目录不存在\n", param[0]);
        } else {
            while((ptr = readdir(dir)) != NULL) {
                printf("%s\n", ptr->d_name);
            }
            closedir(dir);
        }
    }
}